<?php

class RssController extends Zend_Controller_Action {

    public function init() {
        $this->_helper->layout()->disableLayout();
    }

    public function indexAction() {
        $feedData = array(
            'title' => 'Project Geannie Rss Channel',
            'description' => 'This is rss channel of Project Geannie.',
            'link' => 'http://project-tracker-local.com/',
            'category' => 'IT/Web Development/Internet',
            'charset' => 'utf-8',
            'author' => 'savan',
            'rating' => '2',
            'generator' => 'SpearBall Inc.',
//            'entries' => array(
//                array(
//                    'title' => 'Article 1',
//                    'description' => 'Description of Article 1 goes here.',
//                    'link' => 'http://project-tracker-local.com/article1',
//                    'guid' => '1A'
//                )
//                
//            ),
            'entries' => $this->getAllProjects(),
        );
        $feed = Zend_Feed::importArray($feedData, 'rss');
        header('Content-type: text/xml');
        echo $feed->send();
    }

    public function getAllProjects() {
        $projectDb = new Application_Model_Project();
        $projects = $projectDb->fetchAll();
        $array = array();
        foreach ($projects as $project) {
            $localArray = array(
                'title' => $project['name'],
                'description' => $project['description'],
                'link' => 'http://' . $_SERVER['SERVER_NAME'] . '/project/info/' . $project['id'],
                'guid' => $project['id'],
                'category'=>array(
                    array('term'=>'Project Tracker'),
                    array('term'=>'Project')
                ),
            );
            array_push($array, $localArray);
        }
        return $array;
    }
}

